<template>
  <div>
    <el-form class="query-table-form" @submit.native.prevent :inline="true" :model="params">
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="项目名称查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.corp_name"
          placeholder="负责人查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          placeholder="地址查询"
          auto-top
          clearable
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          icon="el-icon-download"
          :loading="exportLoading"
          @click="exportExcel('项目立项（已拒绝）')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <el-tooltip effect="light" :content="scope.row.address">
          <div class="text-truncate">{{ scope.row.address }}</div>
        </el-tooltip>
      </template>

      <template v-slot:itemStatus="scope">
        <span class="badge badge-wrap" :class="`badge-${scope.row.itemStatusStyle}`">
          {{ scope.row.itemStatusLabel }}
        </span>
      </template>

      <template v-slot:refuse="scope">
        <div class="text-truncate" :title="scope.row.confuse_des">{{ scope.row.confuse_des }}</div>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <el-dialog
      :visible.sync="reportVisible"
      :close-on-click-modal="false"
      :before-close="handleCreditClose"
      append-to-body
      top="30px"
      width="80%"
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="数字档案卡" name="file">
          <credit-file :query-id="queryId" :viewMode="viewMode"></credit-file>
        </el-tab-pane>
        <el-tab-pane label="附件">
          <attach-view :queryId="queryId" :visible="reportVisible"></attach-view>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <el-dialog
      :visible.sync="refuseVisible"
      :close-on-click-modal="false"
      append-to-body
      title="拒绝反馈"
      top="30px"
      width="600px"
    >
      <dl class="row">
        <dt class="col-2">拒绝机构：</dt>
        <dd class="col-10">{{ related.item_person_name }}</dd>
      </dl>
      <dl class="row">
        <dt class="col-2">拒绝时间：</dt>
        <dd class="col-10">{{ related.refuseTime }}</dd>
      </dl>
      <dl class="row">
        <dt class="col-2">拒绝理由：</dt>
        <dd class="col-10">{{ related.item_confuse_des }}</dd>
      </dl>
      <div class="text-center mt-5">
        <el-button @click="refuseVisible = false">关闭</el-button>
      </div>
    </el-dialog>
    <attach-cmpt :visible.sync="attachVisible" :customer-related-id="attachRelatedId"></attach-cmpt>
  </div>
</template>

<script>
import SelectAddress from '@/components/select/SelectAddress'
import CreditFile from '@/credit/components/creditFile/CreditCard'

import taskTableMixin from '@/credit/mixin/self/taskTable'

import { enumGuatype, enumItemStatus } from '@/credit/plugins/enumTown'
import { prelimTableColumns } from '@/credit/views/city/self/Preliming'
import AttachView from '@/credit/components/AttachView'
import AttachCmpt from '@/credit/views/city/program/Attach'
export default {
  components: {
    SelectAddress,
    CreditFile,
    AttachView,
    AttachCmpt,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      attachVisible: false,
      attachRelatedId: '',
      params: {
        index: 1,
        size: 10,
        customer_name: '',
        corp_name: '',
        address_code: '',
        'is_approval.eq': 1,
        'gua_type.eq': 2,
        'item_status.neq': 1,
        'confuse_status.eq': 3,
      },
      order: {
        confuse_time: 'DESC',
      },
      tableColumns: [
        ...prelimTableColumns,
        { attrs: { label: '拒绝时间', prop: 'refuseTime', align: 'center' } },
        { attrs: { label: '拒绝角色', prop: 'confuse_person', align: 'center' } },
        { attrs: { label: '拒绝理由', prop: 'confuse_des', align: 'center' }, slot: 'refuse' },
        {
          attrs: { label: '操作', align: 'center', minWidth: 120 },
          operations: [
            // { content: '上传附件', icon: 'fa fa-clipboard', event: this.hanleAttach },
            {
              content: '拒绝反馈',
              icon: 'fa fa-times-circle-o',
              event: this.handleRefuse,
            },
            {
              content: '查看',
              icon: 'fa fa-search',
              event: this.hanleView,
            },
          ],
        },
      ],

      // 立项
      related: {},
      refuseVisible: false,

      activeName: 'file',

      // 档案卡
      queryId: '',
      reportVisible: false,
      viewMode: false,

      // 政府推荐函
      recommendVisible: false,
      recommendData: {},
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getData()
  },
  mounted() {},
  methods: {
    hanleAttach(row) {
      this.attachVisible = true
      this.attachRelatedId = row.customer_related_id
    },
    dataAdapter(item) {
      item.guaType = enumGuatype[item.gua_type] || '-'
      item.refuseTime = this.$utils.dateFormat(item.confuse_time, 'yyyy-MM-dd')

      const itemStatus = enumItemStatus[item.item_status] || {}
      item.itemStatusLabel = itemStatus.label
      item.itemStatusStyle = itemStatus.css

      item.submitType = +item.submit_type
      item.isGovApply = item.submitType === 1

      return item
    },
    handleRefuse(row = {}) {
      this.refuseVisible = true
      this.related = { ...row }
    },
    hanleView(row = {}) {
      this.recommendData = row
      this.queryId = this.recommendData.customer_related_id
      this.viewMode = true
      this.reportVisible = true
    },
    handleCreditClose() {
      this.reportVisible = false
      setTimeout(() => (this.activeName = 'file'), 200)
      if (this.viewMode) {
        return
      }
      this.getData(this.params.index)
    },
  },
}
</script>
<style lang="scss" scoped></style>
